<!-- 
 Copyright 2009 University of  Washington
This code is released under the GPL version 3 - with a copy of the license included
@author Maya Hao Li
 -->

<%
	String clsName = request.getParameter("clsName");

	LimsSession spSession = new LimsSession(request);
	SeedpodUser user = spSession.getUser();

	if (user.canEditData()) {
		if (clsName != null) {
			PManager manager = Seedpod.getPManager();
			ClsMap cls = manager.getModelMap().getClsMap(clsName);
			ArrayList<SlotMap> slots = cls.getSortedSlotMaps();
%>

		<table cellpadding="5" cellspacing="5">
		<tr ><th>Class Name</th>
		<th>User Defined Name</th>
		<th>Instance Label Pattern</th>
		<th>Documentation</th></tr>
		<tr>
		<td><form action="../lims/actionConfigMetadata" id="cls">
		<input type="hidden" id="<%=MetaRdbCls.CLS_ID%>" value="<%=cls.getCID()%>">	<%=cls.getName() %></td>
		<td><input type="text" id="<%=MetaRdbCls.USER_DEFINED_NAME %>" value="<%=cls.getUserDefinedName() %>"></td>
		<td><input type="text" id="<%=MetaRdbCls.BROWSER_PATTERN %>" value="<%=cls.getBrowserPattern() %>"></td>
		<td><textarea  id="<%=MetaRdbCls.DOCUMENTATION %>" rows="2" cols = "20" ><%=cls.getDocumentation()%></textarea></form></td>
		
		</tr>
		</table>
		<hr size=1>
		<table cellpadding="10	" cellspacing="2">
		<tr class="header">
		<th>Attribute Name</th>
		<th>User Defined Name</th>
		<th>Form Widget</th>
		<th>View Widget</th>
		<th>View Sequence</th>
		</tr>
		
		<%
		for ( int i = 0; i < slots.size(); i ++ ) {
			SlotMap s = slots.get(i);
			
			if ( i % 2 == 0 ) 
				out.println("<tr class=\"even\">");
			else 
				out.println("<tr class=\"odd\">");
			
			
			Integer aid = s.getAttributeID();
			String id = "["+aid +"]";
			
			// widget id 
			out.println("<td><form action=\"../lims/actionConfigMetadata\" id=\"slot["+i + "]\"><input type=\"hidden\" id=\""+MetaRdbSlot.AID+"\" value=\"" +aid +"\">"+s.getName()+"</td>");
			// user defined name
			out.println("<td><input type=\"text\" id=\""+MetaRdbSlot.USER_DEFINED_NAME+id+"\"value=\""+s.getDisplayName()+"\"></td>");
			// form widgets
			SelectInput formSelect = new SelectInput(MetaRdbSlot.FORM_WIDGET, s.getFormWidget(), SeedpodModel.RdbCls.FormWidget.toArray());
			out.println("<td>"+s.getFormWidget() + "<br>"+formSelect.render()+"</td>");
			// view widgets
			SelectInput viewSelect = new SelectInput(MetaRdbSlot.VIEW_WIDGET, s.getViewWidget(), SeedpodModel.RdbCls.ViewWidget.toArray() );
			out.println("<td>"+s.getViewWidget() + "<br>"+ viewSelect.render() +"</td>");
			// sequence
			out.println("<td><input type=\"text\" size=\"4\" id=\""+MetaRdbSlot.VIEW_SEQUENCE+id+ "\" value=\""+s.getViewSequence()+"\"></form></td>");
			
			out.println("</tr>");
		}
		%>
		<tr><td >
		<input type="submit" class="CommandButton" value="save changes">
		</td>
		<td >
		<input type="button" class="CommandButton" value="cancel" onclick="window.location.reload()">
		</td>
		</table>
		</form>
	
<%
		}
	}
%>
<%@page import="seedpod.webapp.LimsSession"%>
<%@page import="seedpod.model.custom.*"%>
<%@page import="seedpod.rdb.*"%>
<%@page import="seedpod.model.rdb.*"%>
<%@page import="seedpod.kb2db.*"%>
<%@page import="java.util.*"%>
<%@page import="seedpod.model.*"%>
<%@page import="seedpod.webapp.view.htmlwidget.SelectInput"%>
<%@page import="seedpod.webapp.Seedpod"%>